package com.xdh.springcloud.consumer.helloword.controller;


import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.xdh.springcloud.consumer.helloword.service.PostgresqlService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("postgresql")
public class PostgresqlController {
    @Autowired
    private PostgresqlService postgresqlService;

    @RequestMapping(value = "/queryPostgresql", method = {RequestMethod.GET, RequestMethod.POST})
    @HystrixCommand(fallbackMethod = "addServiceFallback")
    public Object queryPostgresql(String sql) {
        return postgresqlService.queryForList(sql);
    }

    public String addServiceFallback(String sql) {
        return "sql could not excute";
    }
}
